<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .head-nav{
            display: flex;
            justify-content: space-between;
            padding: 10px;
            border-bottom: 1px solid #EEF0F4;
        }

        .list{
            margin: 20px;
        }
        .list ul li{
            list-style: none;
            height: 38px;
            line-height: 38px;
            background: #F7F8FA;
            margin: 10px 0;
            padding: 0px 10px;
            border-radius: 20px;
            font-weight: bold;
            font-size: 14px;
        }
        .list ul li:hover{
            background: #EEF0F4
        }

        /* Dialog */
        .Dialog .box{
            width: 70%;
            position: absolute;
            top: 50%; 
            left: 50%; 
            transform: translate(-50%, -50%);
            border-radius: 8px;
            overflow: hidden;
            text-align: center;
            color: #333;
            z-index: 999;
            background: #fff;
            display: flex;
            flex-wrap: wrap;
            font-weight: 500;
        }
        .Dialog .box>div{
            width: 100%;
        }
        .Dialog .box .Dialog-title{
            padding-top: 10px;
        }
        .Dialog .box .Dialog-content{
            color: #838383;
            padding: 20px 10px;
        }
        .Dialog .box .btn{
            display: flex;
            justify-content: space-between;
            border-top: 1px solid #E2E2E2;
        }
        .Dialog .box .btn>div{
            flex: 1;
            padding: 10px 0px;
            color: #1A73E8;
        }
        .Dialog .box .btn div:nth-child(1){
            border-right: 1px solid #E2E2E2;
        }
        .Dialog .mask{
            background: rgba(20, 20, 20, 0.8);
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            border: 1px solid #333;
        }
    </style>
</head>
<body>
    <div class="head-nav">
        <div onclick="history.go(-1)">《</div>
        <div>弹窗框</div>
        <div></div>
    </div>

    <div class="list">
        <div>消息框</div>
        <ul>
            <li class="confirm">confirm 提示框</li>
            <li class="alert">alert 警告框</li>
        </ul>
    </div>


    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script>

        $('.confirm').click(function(){
            z_confirm("确认要支付吗?",function(){
                console.log("success")
            },function(){
                console.log("fail")
            })
        })

        $('.alert').click(function(){
            z_alert("确认要支付吗?",function(){
                console.log("hello")
            })
        })

        
        function z_confirm(content,res,err){
            let html = $(`<div class="Dialog">
                            <div class="box">
                                <div class="Dialog-title">提示</div>
                                <div class="Dialog-content">${content}</div>
                                <div class="btn">
                                    <div>取消</div>
                                    <div>确定</div>
                                </div>
                            </div>
                            <div class="mask"></div>
                        </div>`)
            $("body").append(html)
            $("body").on('click', '.btn',function(e){
                let text = e.target.innerText
                if(text == "确定"){
                    if ($.isFunction(res)) {
                        res()
                    }
                }else{
                    if ($.isFunction(err)) {
                        err()
                    }
                }
                $(".Dialog").remove()
            })
        }

        function z_alert(content,res,err){
            let html = $(`<div class="Dialog">
                            <div class="box">
                                <div class="Dialog-content">${content}</div>
                                <div class="btn">
                                    <div>确定</div>
                                </div>
                            </div>
                            <div class="mask"></div>
                        </div>`)
            $("body").append(html)
            $("body").on('click', '.btn',function(e){
                let text = e.target.innerText
                if(text == "确定"){
                    if ($.isFunction(res)) {
                        res()
                    }
                }else{
                    if ($.isFunction(err)) {
                        err()
                    }
                }
                $(".Dialog").remove()
            })
        }
    </script>
</body>
</html>